package com.heima.media.controller;


import com.heima.common.dto.PageResponseResult;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "黑马头条频道接口")
public class ChannelController {

    @Autowired
    private IChannelService channelService;

    /**
     * 频道分页请求处理
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "频道分页请求",notes = "author:SpaceTraveller")
    @ApiImplicitParam(name = "dto",value = "请求体对象",required = true,dataType = "ChannelDto")
    public PageResponseResult<List<WmChannel>> listChannelPage(@RequestBody ChannelDto dto){
        return channelService.listChannelPage(dto);
    }

    /**
     * 新增频道的处理
     * @param channel
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增频道的请求",notes = "author:SpaceTraveller")
    @ApiImplicitParam(name = "channel",value = "请求体对象",required = true,dataType = "WmChannel")
    public ResponseResult insertChannel(@RequestBody WmChannel channel){
        return channelService.insertChannel(channel);
    }

    @PutMapping
    @ApiOperation(value = "更新频道的请求",notes = "author:SpaceTraveller")
    @ApiImplicitParam(name = "channel",value = "请求体对象",required = true,dataType = "WmChannel")
    public ResponseResult updateChannel(@RequestBody WmChannel channel){
        return channelService.updateChannel(channel);
    }

    /**
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除频道的请求",notes = "author:SpaceTraveller")
    @ApiImplicitParam(name = "id",value = "请求体对象",required = true,dataType = "Long")
    public ResponseResult deleteChannel(@PathVariable(name = "id") Long id){
        return channelService.deleteChannel(id);
    }
    /**
     *获取频道列表
     * @return
     */
    @GetMapping("/channels")
    @ApiOperation(value = "获取频道列表",notes = "author:SpaceTraveller")
    public ResponseResult getChannels(){
        return channelService.getChannels();
    }


}
